(javaImport
  (java.util
    Collection
    Iterator) )

(de collectionAsCell (Collection)
  (let (internIfString (quote (Object)
                         (let String (pack Object)
                           (if
                             (and Object
                               (sym? Object)
                               (= String Object)
                               (thread String what car eval) )
                             (thread String intern)
                             Object) ) )
        parseObject (quote (Object)
                      (if Object
                        (internIfString
                          (apply
                            (if
                              (and
                                (thread Object java not)
                                (thread Collection.class (.isInstance> Object) java) )
                              'collectionAsCell
                              'javaAsPico) 
                            (list Object) ) )
                        Object) )
        Circular? NIL
        Tail NIL
        Cell (make
               (for (Iterator (.iterator> Collection) (thread Iterator .hasNext> java) )
                 (let Object (thread Iterator .next>)
                   (if (= Object Collection)
                     (if (thread Iterator .hasNext> java)
                       (setq Tail (thread Iterator .next> parseObject) )
                       (setq Circular? T) )
                     (thread Object parseObject link) ) ) ) ) )
  (when Circular?
    (setq Cell (apply 'circ Cell) ) )
  (when Tail
    (queue 'Cell Tail)
    (setq Cell (apply 'cons Cell) ) )
  Cell) )